package Sorting;


import java.awt.Font;
import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Font3D;
import javax.media.j3d.FontExtrusion;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Text3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

/**
 *
 * @author rafael
 */
public class Number {


    public TransformGroup tgNumber;
    public TransformGroup tgNumber1;
    public TransformGroup tgNumber2;
    public int numero;

    public int getNumero() {
        return numero;
    }

    public void setNumero(int numero) {
        this.numero = numero;
    }

    public TransformGroup getTgNumber() {
        return tgNumber;
    }

    public void setTgNumber(TransformGroup tgNumber) {
        this.tgNumber = tgNumber;
    }

    public TransformGroup getTgNumber1() {
        return tgNumber1;
    }

    public void setTgNumber1(TransformGroup tgNumber1) {
        this.tgNumber1 = tgNumber1;
    }

    public TransformGroup getTgNumber2() {
        return tgNumber2;
    }

    public void setTgNumber2(TransformGroup tgNumber2) {
        this.tgNumber2 = tgNumber2;
    }

    public Number(int number, TransformGroup tg){

        addNumber(number);
        addTGNumber(tg);
        addText();

        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    }
    
    public Number(int number, TransformGroup tg0, TransformGroup tg1, TransformGroup tg2){

        addNumber(number);
        addTGNumber(tg0);
        setTgNumber1(tg1);
        setTgNumber2(tg2);
        addText();

        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    }
    
    public Number(int number, TransformGroup tg, int i){

        addNumber(number);
        addTGNumber(tg);
        addTextStack();

        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    }
    
    public Number(int number, TransformGroup tg, float i) {

        addNumber(number);
        addTGNumber(tg);
        addTextQueue();

        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        tgNumber.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    }

    public void addNumber(int n){
    numero = n;
    }

    public void addTGNumber(TransformGroup trans){
    tgNumber = trans;
    }

    public int getNumber(){
    return numero;
    }

    public void setNumber(int number){
    numero = number;
    }

    public TransformGroup getTGNumber(){
    return tgNumber;
    }
    
    public void addText() {

        Font3D fonte = new Font3D(new Font("Century Gothic", Font.BOLD, 1), new FontExtrusion());
        Text3D texto;
        if (numero == -1) {
            texto = new Text3D(fonte, new String(""), new Point3f(0.0f, 0.0f, 0.0f));    
        } else {
            texto = new Text3D(fonte, new String(Integer.toString(numero)), new Point3f(0.0f, 0.0f, 0.0f));
        }
        Appearance aparencia = new Appearance();

        ColoringAttributes corAP = new ColoringAttributes(new Color3f(0.3f, 0.2f, 0.7f), 1);
        aparencia.setColoringAttributes(corAP);

        Shape3D aparenciaTexto = new Shape3D(texto);

        aparenciaTexto.setAppearance(aparencia);

        Transform3D tfTexto = new Transform3D();
        tfTexto.setScale(Main.raio * 2 - 0.1f);

        tfTexto.setTranslation(new Vector3f(-Main.raio/2, -Main.raio/2, Main.raio));
        TransformGroup tgTexto = new TransformGroup(tfTexto);

        tgTexto.addChild(aparenciaTexto);
        tgNumber.addChild(tgTexto);

    }
    
    public void addTextStack() {

        Font3D fonte = new Font3D(new Font("Century Gothic", Font.BOLD, 1), new FontExtrusion());
        Text3D texto = new Text3D(fonte, new String(Integer.toString(numero)), new Point3f(0.0f, 0.0f, 0.0f));

        Appearance aparencia = new Appearance();

        ColoringAttributes corAP = new ColoringAttributes(new Color3f(0.3f, 0.2f, 0.7f), 1);
        aparencia.setColoringAttributes(corAP);

        Shape3D aparenciaTexto = new Shape3D(texto);

        aparenciaTexto.setAppearance(aparencia);

        Transform3D tfTexto = new Transform3D();
        tfTexto.setScale(Main.raio * 2 - 0.1f);

        tfTexto.setTranslation(new Vector3f(-Main.raio/2, -Main.raio/2, 0.4f));
        TransformGroup tgTexto = new TransformGroup(tfTexto);

        tgTexto.addChild(aparenciaTexto);
        tgNumber.addChild(tgTexto);

    }
    
    public void addTextQueue() {

        Font3D fonte = new Font3D(new Font("Century Gothic", Font.BOLD, 1), new FontExtrusion());
        Text3D texto = new Text3D(fonte, new String(Integer.toString(numero)), new Point3f(0.0f, 0.0f, 0.0f));

        Appearance aparencia = new Appearance();

        ColoringAttributes corAP = new ColoringAttributes(new Color3f(0.3f, 0.2f, 0.7f), 1);
        aparencia.setColoringAttributes(corAP);

        Shape3D aparenciaTexto = new Shape3D(texto);

        aparenciaTexto.setAppearance(aparencia);

        Transform3D tfTexto = new Transform3D();
        tfTexto.setScale(Main.raio * 2 - 0.1f);

        tfTexto.setTranslation(new Vector3f(-Main.raio/2, -Main.raio/2, 0.15f));
        TransformGroup tgTexto = new TransformGroup(tfTexto);

        tgTexto.addChild(aparenciaTexto);
        tgNumber.addChild(tgTexto);

    }
    
    public void hideLeft() {
        Transform3D tf = new Transform3D();
        tgNumber1.getTransform(tf);
        tf.setTranslation(new Vector3f(0.0f, 0.0f, 9999f));
        tgNumber1.setTransform(tf);
    }
    
    public void hideRight() {
        Transform3D tf = new Transform3D();
        tgNumber2.getTransform(tf);
        tf.setTranslation(new Vector3f(0.0f, 0.0f, 9999f));
        tgNumber2.setTransform(tf);
    }
    
    public void showLeft() {
        Transform3D tf = new Transform3D();
        tgNumber1.getTransform(tf);
        tf.setTranslation(new Vector3f(-Main.raio, 0.0f, 0.0f));
        tgNumber1.setTransform(tf);
    }
    
    public void showLeft(float y) {
        Transform3D tf = new Transform3D();
        tgNumber1.getTransform(tf);
        tf.setTranslation(new Vector3f(-Main.raio, 0.05f, 0.0f));
        tgNumber1.setTransform(tf);
    }
    
    public void showRight() {
        Transform3D tf = new Transform3D();
        tgNumber2.getTransform(tf);
        tf.setTranslation(new Vector3f(Main.raio, 0.0f, 0.0f));
        tgNumber2.setTransform(tf);
    }
    
    public void showRight(float y) {
        Transform3D tf = new Transform3D();
        tgNumber2.getTransform(tf);
        tf.setTranslation(new Vector3f(Main.raio, -0.05f, 0.0f));
        tgNumber2.setTransform(tf);
    }

}
